<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page contentType = "text/html; charset=UTF-8" %>

<html>
<head>

<c:set var="cssFileName">
	<c:out value="${crudViewMeta.cssFileName}" default="default.css"/>
</c:set>
<link rel="stylesheet" href="<c:url value='/css/${cssFileName}'/>" type="text/css">
<link rel="stylesheet" href="<c:url value='/css/calendar-win2k-1.css'/>">

<title>新增<c:out value="${crudMeta.title}"/>记录页面</title>

<script type="text/javascript" src="<c:url value='/javascript/calendar.js'/>"></script>
<script type="text/javascript" src="<c:url value='/javascript/lang/calendar-zh.js'/>"></script>
<script type="text/javascript" src="<c:url value='/javascript/calendar-setup.js'/>"></script>
<script type="text/javascript">
function gotoListView()
{
	window.location="<c:url value='/list.do'><c:param name='name' value='${crudMeta.beanName}'/>
	<c:forEach items='${crudMeta.otherWantedParameters}' var='wantedParam'>
    	<c:param name='${wantedParam}' value='${param[wantedParam]}'/>
    </c:forEach></c:url>";
}

function submitFormForRefresh()
{
	listForm.requestForm.value = "true";
	listForm.submit();
}
</script>

</head>

<body>

<table class="top" align="center">
	<tr><td class="headtitle">新增<c:out value="${crudMeta.title}"/></td></tr>
</table>


<form name="listForm" action="<c:url value='/add.do'/>" method="POST"/>
	<input type="hidden" name="name" value="<c:out value='${crudMeta.beanName}'/>"/>
	<input type="hidden" name="requestForm" value="false">
	<c:forEach items="${crudMeta.otherWantedParameters}" var="wantedParam">
		<input type="hidden" name="<c:out value='${wantedParam}'/>" value="<c:out value='${param[wantedParam]}'/>">
	</c:forEach>

	<table class="content">
    
	  <c:forEach items="${crudMeta.columnMetas}" var="col">
	  	<spring:bind path="command.mapContent[${col.colName}]">
	     	<c:set var="validateError"><c:out value="${status.errorMessage}" default=""/></c:set>
		</spring:bind>
		
	  	<c:if test="${!col.derived}">
	  	<tr class="body">
	  		<c:if test="${col.showInAddForm}">
      		<td class="head">
      			<c:if test="${empty validateError}"><c:out value="${col.title}"/></c:if>
      			<c:if test="${not empty validateError}"><span class="validateError"><c:out value="${col.title}"/></span></c:if>
      			<c:if test="${!col.nullable}"><span class="notNullHint">*</span></c:if>
      		</td>
      		<td>
      		
      		
      		<!--相应列没有设置字典-->
  			<c:if test="${empty col.dictName}">
  				<spring:bind path="command.mapContent[${col.colName}]">
  					<c:choose>
  						<c:when test="${col.inputable}">
  						
  							<!--如果用户可以直接手工输入，或者没有dispPattern，则使用一个表单元素就可以了-->
		      				<c:if test="${col.directInputable}">
			  					<input type="text" id="input_<c:out value='${col.colName}'/>"
			  						name="<c:out value='${status.expression}'/>" 
			  						value="<c:out value='${status.value}'/>" <c:if test="${!col.directInputable}">readonly</c:if>>
				      			<c:if test="${not empty col.inputValueSelectViewName}">
				      				<c:import url="/WEB-INF/jsp/crud/inputValueSelect/${col.inputValueSelectViewName}.jsp">
				      					<c:param name="name" value="${crudMeta.beanName}"/>
				      					<c:param name="formItemName" value="mapContent[${col.colName}]"/>
				      					<c:param name="formItemId" value="input_${col.colName}"/>
				      				</c:import>
				      			</c:if>
			      			</c:if>
			      			
			      			<!--如果用户不可以直接手工输入-->
			      			<c:if test="${!col.directInputable}">
			  					<input type="hidden" id="ID_<c:out value='${col.colName}'/>"
			  						name="<c:out value='${status.expression}'/>" 
			  						value="<c:out value='${status.value}'/>" <c:if test="${!col.directInputable}">readonly</c:if>
			  						onchange="javascript:<c:out value='${col.colName}'/>_onchange();">
				      			<input type="text" name="DISP_<c:out value='${col.colName}'/>" disabled>
				      			<c:if test="${not empty col.inputValueSelectViewName}">
				      				<c:import url="/WEB-INF/jsp/crud/inputValueSelect/${col.inputValueSelectViewName}.jsp">
				      					<c:param name="name" value="${crudMeta.beanName}"/>
				      					<c:param name="colName" value="${col.colName}"/>
				      					<c:param name="formItemName" value="mapContent[${col.colName}]"/>
				      					<c:param name="formItemId" value="ID_${col.colName}"/>
				      					<c:param name="formItem4DispName" value="DISP_${col.colName}"/>
				      				</c:import>
				      			</c:if>
			      			</c:if>
  						</c:when>
  						
  						<c:otherwise>
							<input type="hidden" 
								name="<c:out value='${status.expression}'/>" 
								value="<c:out value='${status.value}'/>">      						
							<c:out value='${status.value}'/>
  						</c:otherwise>
  					</c:choose>
  				</spring:bind>
  				
  			</c:if>
      		
      		<!--列有对应字典-->
  			<c:if test="${not empty col.dictName}">
  				<spring:bind path="command.mapContent[${col.colName}]">
					<select name="<c:out value='${status.expression}'/>">
						<c:if test="${!col.primaryKey}"><option value="">(未选定)</option></c:if>
						<c:forEach var="map" items="${col.dictMap}">										
							<option value='<c:out value="${map.key}"/>' <c:if test="${map.key == status.value}">selected="selected"</c:if>><c:out value="${map.value}"/></option>
						</c:forEach>
					</select>
				</spring:bind>
			</c:if>
			
			&nbsp;&nbsp;<span class="hint"><c:out value="${col.hint}"/></span>
			<!--仅仅为了形式上的美观-->
			<c:if test="${not empty col.hint}">&nbsp;&nbsp;</c:if>
			<!--显示校验信息-->
			<span class="validateError"><c:out value="${validateError}"/></span>
			
      		</td>
      		</c:if>
      		
      		<c:if test="${!col.showInAddForm}">
      			<spring:bind path="command.mapContent[${col.colName}]">		
					<input type="hidden" 
						name="<c:out value='${status.expression}'/>" 
						value="<c:out value='${status.value}'/>">      						
  				</spring:bind>
      		</c:if>
      	</tr>
      	</c:if>
	  </c:forEach>	
		
	</table>

<br>
	
<table>
	<tr align="center" valign="center">
		<td align="left" width="50%">
			<input type="submit" name="save" value="保存">
			<input type="button" name="back" value="返回" onclick="javascript:gotoListView()">
		</td>
		<td width="50%">
		</td>
	</tr>
</table>
 	
</form>
</body>
</html>